#include <algorithm>
#include <cstdio>
#include <vector>

const int N = 300005;
int n, m;
int a[N], dep[N], perans[N], casans[N], rt[N], c[N];
long long s[N], v[N], h[N], ad[N], mul[N];
std::vector<int> e[N];

struct Node {
  int d, ch[2];
  long long val;
} node[N];

inline void add(int u, int v) { e[u].push_back(v); }

inline void pushdown(int x) {
  static int ls, rs;
  if (ad[x] != 0 || mul[x] != 1) {
    if ((ls = node[x].ch[0])) {
      mul[ls] *= mul[x];
      ad[ls] *= mul[x];
      ad[ls] += ad[x];
      node[ls].val *= mul[x];
      node[ls].val += ad[x];
    }
    if ((rs = node[x].ch[1])) {
      mul[rs] *= mul[x];
      ad[rs] *= mul[x];
      ad[rs] += ad[x];
      node[rs].val *= mul[x];
      node[rs].val += ad[x];
    }
    ad[x] = 0, mul[x] = 1;
  }
}

int merge(int x, int y) {
  if (!x || !y) return x | y;
  pushdown(x), pushdown(y);
  if (node[x].val > node[y].val) std::swap(x, y);
  node[x].ch[1] = merge(node[x].ch[1], y);
  if (node[node[x].ch[0]].d < node[node[x].ch[1]].d) std::swap(node[x].ch[0], node[x].ch[1]);
  node[x].d = node[node[x].ch[1]].d + 1;
  return x;
}

inline void pop(int &x) { x = merge(node[x].ch[0], node[x].ch[1]); }

inline long long top(int x) { return node[x].val; }

void dfs(int x) {
  for (std::vector<int>::iterator i = e[x].begin(); i != e[x].end(); ++i) {
    dep[*i] = dep[x] + 1;
    dfs(*i);
    rt[x] = merge(rt[x], rt[*i]);
  }
  pushdown(rt[x]);
  while (rt[x] && top(rt[x]) < h[x]) {
    pushdown(rt[x]);
    perans[rt[x]] = dep[c[rt[x]]] - dep[x];
    pop(rt[x]);
    ++casans[x];
  }
  if (a[x])
    mul[rt[x]] *= v[x], node[rt[x]].val *= v[x];
  else
    ad[rt[x]] += v[x], node[rt[x]].val += v[x];
}
int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("P3261 [JLOI2015]城池攻占.in", "r", stdin);
  freopen("P3261 [JLOI2015]城池攻占.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &h[i]);
    mul[i] = 1;
  }
  for (int i = 2, tmp; i <= n; ++i) {
    scanf("%d%d%lld", &tmp, &a[i], &v[i]);
    add(tmp, i);
  }
  for (int i = 1; i <= m; ++i) {
    scanf("%lld%d", &s[i], &c[i]);
    node[i].val = s[i];
    rt[c[i]] = merge(rt[c[i]], i);
  }
  dep[1] = 1;
  dfs(1);
  while (rt[1]) {
    perans[rt[1]] = dep[c[rt[1]]];
    pop(rt[1]);
  }
  for (int i = 1; i <= n; ++i) {
    printf("%d\n", casans[i]);
  }
  for (int i = 1; i <= m; ++i) {
    printf("%d\n", perans[i]);
  }
  return 0;
}